package app.itw.tison.cloud.product_service.service.impl;

import app.itw.tison.cloud.model.Product;
import app.itw.tison.cloud.product_service.service.ProductService;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Service;


@Service
public class ProductServiceImpl implements ProductService {

  //初始化假数据
  private static List<Product> list = new ArrayList<>();

  static {
    for (int i = 1; i <= 100; i++) {
      list.add(new Product(i + "", "商品" + i, new Date(), 100 + i * 10, "商品" + i + "正在热卖中呢！！",
          1
      ));
    }
  }


  @Override
  public Product getProductByID(String id) {
    for (Product product : list) {
      if (product.getId().equals(id)) {
        return product;
      }
    }
    return null;
  }

  //查询list
  @Override
  public List<Product> getProductList() {
    return list;
  }

  @Override
  public List<Product> getProductByIds(List<String> ids) {


    List<Product> pList = new ArrayList<Product>();
    ids.forEach(id->{
      list.forEach(itme->{
        if (itme.getId().equals(id)) {
          pList.add(itme);
          return;
        }
      });
    });
    System.out.println(pList);
    return pList.size() > 0 ? pList : null;
  }


}
